package soul.resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import soul.mapper.HealthDao;

/**
 * Created by sunzhengjie on 2016/11/17.
 */
@Controller
@RequestMapping("/health")
public class HealthResource {

    private static final Logger LOGGER = LoggerFactory.getLogger(HealthResource.class);

    @Autowired
    HealthDao dao;

    @RequestMapping()
    @ResponseBody
    public String health() {
        LOGGER.info("test health");
        LOGGER.error("test health");
        try{
            return dao.dataBaseHealth() == 1 ? "alive123" : "database died";
        }catch (Exception ex){
            LOGGER.error("database died");
            return "database die";
        }
    }
}
